package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.mapper.DishMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     * @param dishDTO
     * @return
     */
    @ApiOperation("新增菜品接口")
    @PostMapping
    public Result addDish(@RequestBody DishDTO dishDTO){
        dishService.addDish(dishDTO);
        return Result.success();
    }

    /**
     * 菜品分页条件查询
     * @param dishPageQueryDTO
     * @return
     */
    @ApiOperation("菜品分页条件查询")
    @GetMapping("/page")
    public Result<PageResult> dishPage(DishPageQueryDTO dishPageQueryDTO){
        PageResult page = dishService.dishPage(dishPageQueryDTO);
        return Result.success(page);
    }


    /**
     * 根据id查询菜品和菜品口味
     * @param id
     * @return
     */
    @ApiOperation("根据id查询菜品和菜品口味")
    @GetMapping("/{id}")
    public Result<DishVO> getDishWithFlavorById(@PathVariable("id") Long id){
        DishVO dishVO = dishService.getDishWithFlavorById(id);
        return Result.success(dishVO);
    }


    /**
     * 根据id批量删除菜品
     * @param ids
     * @return
     */
    @ApiOperation("批量删除菜品")
    @DeleteMapping
    public Result deleteBatchDishById(@RequestParam List<Long> ids){
        dishService.deleteBatchDishById(ids);
        return Result.success();
    }


    /**
     * 修改菜品
     * @param dishDTO
     * @return
     */
    @ApiOperation("修改菜品")
    @PutMapping
    public Result updateDishById(@RequestBody DishDTO dishDTO){
        dishService.updateDishById(dishDTO);
        return Result.success();
    }


    /**
     * 起售停售菜品
     * @param status
     * @param id
     * @return
     */
    @ApiOperation("起售停售菜品")
    @PostMapping("/status/{status}")
    public Result updateDishStatus(@PathVariable("status") Integer status,@RequestParam("id") Long id){
        dishService.updateDishStatus(status,id);
        return Result.success();
    }


    /**
     * 根据分类id查菜品
     * @param categoryId
     * @return
     */
    @ApiOperation("根据分类id查菜品")
    @GetMapping("/list")
    public Result getDishesByCategoryId(Long categoryId){
        List<Dish> dishList = dishService.getDishesByCategoryId(categoryId);
        return Result.success(dishList);
    }
}
